package com.lg.concurrent.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 * 同步移交队列
 *
 * 长度为 0
 * 必须有等待线程
 * 才可以 add
 */
public class SynchronousQueueTest {
    public static void main(String[] args) throws InterruptedException {
        //SynchronousQueue
        ExecutorService pool1 = Executors.newCachedThreadPool();

        /**
         *
         */
        SynchronousQueue synchronousQueue = new SynchronousQueue();
        new Thread(()->{
            try {
                System.out.println(synchronousQueue.take() );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }).start();

        new Thread(()->{
            try {
                System.out.println(synchronousQueue.take() );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }).start();

        TimeUnit.MICROSECONDS.sleep(100);
        synchronousQueue.add("a");
        synchronousQueue.add("321");


    }
}
